package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.order.mapper.OrderVerificationCodeMapper;
import cn.stylefeng.guns.modular.order.model.Order;
import cn.stylefeng.guns.modular.order.mapper.OrderMapper;
import cn.stylefeng.guns.modular.order.model.OrderVerificationCode;
import cn.stylefeng.guns.modular.order.service.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>OrderController
 *
 * @author yangyu
 * @since 2019-12-10
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    IOrderVerificationCodeService orderVerificationCodeService;
    @Autowired
    OrderMapper orderMapper;

    @Override
    public Page<Map<String, Object>> selectOrders(Integer userId) {
        Page page = LayuiPageFactory.defaultPage();
        return orderMapper.selectOrders(page,userId);
    }

    @Override
    public boolean saveOrder(Order order) {

        try {
            order.setCreateTime(new Date());

//            String verificationCode = order.getVerificationCode();
//            if(!StringUtils.isEmpty(verificationCode)){
//                OrderVerificationCode code = orderVerificationCodeService.verifyCode(verificationCode);
//                if(null != code){
//                    code.setStatus(1);
//                    code.setUpdateTime(new Date());
//                    orderVerificationCodeService.updateById(code);
//                }else{
//                    return false;
//                }
//            }


            orderMapper.insert(order);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }


    }
}
